package com.hotel.config.rabbitmq.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;

import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Handler;

// 客服的消息队列
@Configuration
public class TMC_WS_Delay_DirectConfig {
//    创建交换机
    public static final String TMC_DELAY_EXCHANGE = "TMC_ws_delay_exchange";
//    创建死信队列
    public static final String TMC_DELAY_QUEUE = "TMC_ws_delay_queue";
//    进行绑定
    public static final String TMC_DELAY_BING = "TMC_ws_delay_bing";
//    创建密钥
    public static final String TMC_DELAY_KEY = "TMC_ws_delay_key";
//  1.创建交换机
    @Bean(TMC_DELAY_EXCHANGE)
    public CustomExchange newExchangeWS(){
        Map<String,Object> map=new HashMap<>();
//        交换机的类型
        map.put("x-delayed-type","direct");
//        交换机的名称   交换机的类型  是否持久化  是否自动删除 参数
       return new CustomExchange(TMC_DELAY_EXCHANGE,"x-delayed-message",true,false,map);
    }
//  2.  创建队列
    @Bean(TMC_DELAY_QUEUE)
    public Queue newQueueWS(){
        return new Queue(TMC_DELAY_QUEUE,true,false,false);
    }
//    3.将交换机和队列绑定
    @Bean(TMC_DELAY_BING )
    public Binding bindingWS(){
//         绑定队列通过交换机使用密钥
        return BindingBuilder.bind(newQueueWS()).to(newExchangeWS()).with(TMC_DELAY_KEY).noargs();
    }


}
